package com.fruit.controller.wap.traceback;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fruit.controller.base.BaseController;
import com.fruit.pojo.common.Page;
import com.fruit.service.rights.TraceBackManager;
import com.fruit.util.CommonUtil;
import com.fruit.util.ResultInfo;

import lombok.extern.slf4j.Slf4j;
/**
 * 追溯记录Contraller
 * @author Administrator
 * @version 2018.01.03 12:20
 */
@Slf4j
@Controller
@RequestMapping(value = "/wap/traceback")
public class TraceBackController extends BaseController {
	@Autowired
	private TraceBackManager traceBackManager;
	/**
	 * 获取追溯商品的维护记录
	 * @param page 页面对象
	 * @param request 请求对象
	 * @return Map<String, Object>
	 */
	@RequestMapping(value = "/getTraceBacks", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public Map<String, Object> getTraceBacks(Page page, HttpServletRequest request) {
		log.info("【追溯记录】---【开始】--");
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			String id = request.getParameter("id");
			Map<String, Object> pam = new HashMap<String, Object>();
			pam.put("startNum",  (page.getPage() - 1) * page.getShowNum());
			pam.put("pageNum", page.getShowNum());
			pam.put("id", Integer.valueOf(id));
			String tradeId = CommonUtil.getUUID();
			result = traceBackManager.getTbRecords(tradeId, pam);
		} catch (Exception e) {
			log.info("【追溯记录】---【异常】---{}", e);
			result.put("result", this.initResult(ResultInfo.ERROR, "exception", "系统异常"));
		}
		log.info("【追溯记录】---【结束】--");
		return result;
	}
}
